package com.atguigu.read;

import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import io.searchbox.core.Search;
import org.elasticsearch.search.builder.SearchSourceBuilder;

/**
 * @author Lec
 * @date 2022/7/20 0:11
 */

public class Es04_APIRead {
    public static void main(String[] args) {
        //1.创建客户端工厂
        JestClientFactory jestClientFactory = new JestClientFactory();

        //2.设置链接地址
        HttpClientConfig httpClientConfig = new HttpClientConfig.Builder("http://hadoop102:9200")
                .build();
        jestClientFactory.setHttpClientConfig(httpClientConfig);

        //3.获取客户端链接
        JestClient jestClient = jestClientFactory.getObject();

        //4.读取ES数据

        //使用API组成查询语句
        //TODO --------------------------------------{}------------------------------------------
        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();

        Search search = new Search.Builder(sourceBuilder.toString()).build();

        //关闭连接
        jestClient.shutdownClient();

    }
}
